<?php
/*
	获取活动详情
	电商客商品列表页和商品详情页会调用本方法以获得商品详情
*/
defined('BY_JYA') or exit('error');
list($goods_id,$optionid,$mid)=$arguments;
$mid=$mid?:$_SESSION['uid'];
$member=$this->get('member',array('mid'=>$mid));
$setting=$this->plugin_setting('setting');
if(!$setting['showgetfee']){
	return false;
}else if($setting['showgetfee']==2){
	if(!$member['is_agent'] || $member['stop']){
		return false;
	}
}
$ignore=$this->get('goods',array('goods_id'=>$goods_id),array('id','ignore','commissions'));
if($optionid){
	$goodsinfo=pdo_get('jy_weishop_goods_option',array('goodsid'=>$goods_id,'id'=>$optionid),array('costprice','price'));
}else{
	$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$goods_id),array('costprice','price'));
}
$goodsprice=$goodsinfo['price'];
$goodscostprice=$goodsinfo['costprice'];
if($setting['get_buyordernum']!=1 && $ignore['id'] && $ignore['ignore']!=1){
	$goods_commission['commissions']=$ignore['commissions']?json_decode($ignore['commissions'],true):array();
	foreach($goods_commission['commissions'] as $gc){
					if($gc['level_id']==0){
						$demogoods_commission_per=$gc['commission1'];
					}
					if($gc['level_id']!=$member['level_id']){
						continue;
					}else{
						$goods_commission_per=$gc['commission1'];
						break;
					}
	}
	$goods_commission_per=$goods_commission_per?:$demogoods_commission_per;	
	if(substr($goods_commission_per,-1)=='%'){
					//利润计算
					if($setting['commissionfeetype']==2){
						$goodsprice -=$goodscostprice;
					}
					$goods_commission_money=($goodsprice*substr($goods_commission_per,0,-1))/100;
	}else{
					$goods_commission_money=$goods_commission_per;
	}
	$goods['commission_money']=$goods_commission_money?price($goods_commission_money,true):0;
}elseif(!$ignore['id']){
	if(!$member['level_id']){
				//获取默认等级佣金比例
				$level_commissions=$this->plugin_setting('default_level');
				$level_id=0;
				$commission_per=$level_commissions['commission1'];
	}else{
				$level=$this->get('level',array('id'=>$member['level_id'],'uniacid'=>$_SESSION['uniacid']));
				$level_commissions=json_decode($level['commissions'],true);
				$level_id=$level['id'];
				$commission_per=$level_commissions['commission1'];
	}
	if($setting['get_buyordernum']!=1){
		//利润计算
		if($this->setting['commissionfeetype']==2){
			$goodsprice -=$goodscostprice;
		}
		$order_commission_money=intval($goodsprice*$commission_per)/100;
	}else{//按笔分销
		$order_commission_money=$commission_per;
	}
	$goods['commission_money']=$order_commission_money>0?price($order_commission_money,true):0;
}else{
	$goods['commission_money']='0.00';
}
$goods['commission_title']=$setting['showgettitle']?:'预估赚';
$goods['commission_sysbutie']=price($setting['sysbutie'],true);
return $goods;